package org.itboys.mongodb.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.itboys.commons.utils.time.TimeUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 作者：jiangxiong
 * 日期：2017年2月8日
 * 联系方式 ：empty90911@126.com
 * 描述：mysql实体基类
 *
 */
public class BaseMySqlEntity implements Serializable{
	private static final long serialVersionUID = 4747935309941295435L;

	protected Long id; //主键

    private Long creator;//数据创建者ID

  //  private String creatorName;//数据创建者昵称


	@JsonIgnore
	private Date ct;//创建时间。只存储，不输出。实际输出，createTime(年月日，时分秒)和createDate(年月日)
	@JsonIgnore
	private Date ut;//修改时间。只存储，不输出。实际输出，updateTime(年月日，时分秒)和updateDate(年月日)

	private Long updater;//数据最后修改者ID。

//    private String updaterName;//数据最后修改者昵称。

	
    private Integer isDeleted;//是否删除，否为0，是为1

	//获取创建时间-(年月日，时分秒)
	public String getCreateTime() {

		return TimeUtils.format(ct,"yyyy-MM-dd HH:mm:ss");
	}
	//获取创建时间-(年月日)
	public String getCreateDate() {
		//if(ct!=null){
			return TimeUtils.format(ct,"yyyy-MM-dd");
		//}

	}
	//获取修改时间-(年月日，时分秒)
	public String getUpdateTime() {

		return TimeUtils.format(ut,"yyyy-MM-dd HH:mm:ss");
	}
	//获取修改-(年月日)
	public String getUpdateDate() {
		return TimeUtils.format(ut,"yyyy-MM-dd");
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCreator() {
		return creator;
	}

	public void setCreator(Long creator) {
		this.creator = creator;
	}

/*	public String getCreatorName() {
		return creatorName;
	}

	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}*/

	public Date getCt() {
		return ct;
	}

	public void setCt(Date ct) {
		this.ct = ct;
	}

	public Date getUt() {
		return ut;
	}

	public void setUt(Date ut) {
		this.ut = ut;
	}

	public Long getUpdater() {
		return updater;
	}

	public void setUpdater(Long updater) {
		this.updater = updater;
	}

/*	public String getUpdaterName() {
		return updaterName;
	}

	public void setUpdaterName(String updaterName) {
		this.updaterName = updaterName;
	}*/

	public Integer getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(Integer isDeleted) {
		this.isDeleted = isDeleted;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;

		if (obj.getClass().equals(this.getClass()) && (obj instanceof BaseMySqlEntity)) {
			BaseMySqlEntity entity = (BaseMySqlEntity) obj;
			Long eid = entity.getId();
			if (eid == null || id == null)
				return false;
			else
				return eid.longValue() == id.longValue();
		} else
			return false;
	}
	
	

	@Override 
    public int hashCode() { 
            return HashCodeBuilder.reflectionHashCode(this); 

    }

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
